﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using Microsoft.Office.Project.EPMAuditing.Library;
using System.IO;

namespace Microsoft.Office.Project.EPMAuditing.AuditListenerCatalog
{
    class XMLFileAuditListener  : BaseFileAuditListener
    {
        protected override string NewFileName()
        {
            return String.Format(CultureInfo.InvariantCulture, "{0}{1} {2}.xml", FileDirectory, FileBaseName,
                DateTime.Now.ToString("yyyyMMdd-HHmmss", DateTimeFormatInfo.InvariantInfo));
        }

        public override void Write(MemoryStream ms)
        {
            //ChangeRecord changeRecord = DeserializeMessage(ms);
            ChangeRecord changeRecord = new ChangeRecord(ms);
            changeRecord.TracingService = TracingService;
            base.WriteToFile(changeRecord.ToXml());
        }

        protected override void AddHeader()
        {
            base.WriteToFile(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
            base.WriteToFile(string.Format(CultureInfo.InvariantCulture, @"<EPMAuditLog Created=""{0}"">", DateTime.Now.ToString()));
        }

        protected override void AddFooter()
        {
            base.WriteToFile("</EPMAuditLog>");
        }

    }
}
